<?php
/**
 * Created by PhpStorm.
 * User: zhang
 * Date: 2018/4/28
 * Time: 20:15
 */
namespace app\account\model;

class User_id_util{
    function createRandomID($uid) {
        $str = $uid + "";
        $uid = '';
        for ($i = 0, $len = strlen($str); $i < $len; $i++) {
            $s = substr($str, $i, 1);
            switch ($s) {
                case '0':
                    $arry = array("i", "R", "g", "0", "K", "s");
                    $cursor = array_rand($arry);
                    $uid = $uid . ($arry[$cursor] . '');
                    break;
                case '1':
                    $arry = array("1", "q", "f", "c", "Q", "V",);
                    $cursor = array_rand($arry);
                    $uid = $uid . ($arry[$cursor] . '');
                    break;
                case '2':
                    $arry = array("2", "w", "v", "X", "N", "D");
                    $cursor = array_rand($arry);
                    $uid = $uid . ($arry[$cursor] . '');
                    break;
                case '3':
                    $arry = array("3", "e", "h", "I", "C", "M");
                    $cursor = array_rand($arry);
                    $uid = $uid . ($arry[$cursor] . '');
                    break;
                case '4':
                    $arry = array("4", "j", "O", "L", "J", "p");
                    $cursor = array_rand($arry);
                    $uid = $uid . ($arry[$cursor] . '');
                    break;
                case '5':
                    $arry = array("5", "t", "G", "k", "Y", "a");
                    $cursor = array_rand($arry);
                    $uid = $uid . ($arry[$cursor] . '');
                    break;
                case '6':
                    $arry = array("6", "y", "l", "U", "A", "d");
                    $cursor = array_rand($arry);
                    $uid = $uid . ($arry[$cursor] . '');
                    break;
                case 7:
                    $arry = array("7", "u", "B", "b", "E", "S");
                    $cursor = array_rand($arry);
                    $uid = $uid . ($arry[$cursor] . '');
                    break;
                case '8':
                    $arry = array("H", "r", "8", "P", "F", "x");
                    $cursor = array_rand($arry);
                    $uid = $uid . ($arry[$cursor] . '');
                    break;
                case '9':
                    $arry = array("m", "9", "n", "W", "o", "T");
                    $cursor = array_rand($arry);
                    $uid = $uid . ($arry[$cursor] . '');
                    break;
                default:
                    break;
            }
        }
        return $this->setIDPrefix($uid);
    }

    /**
     * 设置id的前缀
     * @param type $uid 用户id
     *
     */
    function setIDPrefix($uid) {
        if (strlen($uid) >= 12) {
            return $uid;
        } else {
            if (strlen($uid) >= 11) {
                return 'Z' . $uid;
            } else {
                $length = 11 - strlen($uid);
                $str = 'abcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY'; //62个字符
                $str = str_shuffle($str);
                return substr($str, 0, $length) . 'Z' . $uid;
            }
        }
    }
}